<template>
  <div class="hm_layout">
    <!-- 二级路由出口 -->
    <router-view></router-view>
    <!-- 底部导航栏 -->
    <van-tabbar
      v-model="active"
      active-color="#ee0a24"
      inactive-color="#000"
      route
    >
      <van-tabbar-item icon="notes-o" to="/article">面经</van-tabbar-item>
      <van-tabbar-item icon="star-o" to="/collect">收藏</van-tabbar-item>
      <van-tabbar-item icon="like-o" to="/like">喜欢</van-tabbar-item>
      <van-tabbar-item icon="friends-o" to="/user">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: "HmLayout",
  data() {
    return {
      active: 0,
    };
  },
  watch: {
    $route(to) {
      if (to.path === "/article") {
        this.active = 0;
      } else if (to.path === "/collect") {
        this.active = 1;
      } else if (to.path === "/like") {
        this.active = 2;
      } else if (to.path === "/user") {
        this.active = 3;
      }
    },
  },
};
</script>

<style></style>
